public class code3 {
    //两个数不同二进制的个数
    public int hammingDistance(int x, int y) {
        int z = x^y;
        return hammingWeight(z);
    }
    //n&(n-1)
    public int hammingWeight(int n) {
        int ret = 0;
        while(n!=0) {
            n &= (n-1);//变最右侧的1为0
            ret++;//每减少一个1ret++
        }
        return ret;
    }
}
